package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MesTecPro;
import com.ruoyi.system.service.IMesTecProService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工艺工序Controller
 * 
 * @author ruoyi
 * @date 2024-06-01
 */
@RestController
@RequestMapping("/system/pro")
public class MesTecProController extends BaseController
{
    @Autowired
    private IMesTecProService mesTecProService;

    /**
     * 查询工艺工序列表
     */
    @PreAuthorize("@ss.hasPermi('system:pro:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesTecPro mesTecPro)
    {
        startPage();
        List<MesTecPro> list = mesTecProService.selectMesTecProList(mesTecPro);
        return getDataTable(list);
    }

    /**
     * 导出工艺工序列表
     */
    @PreAuthorize("@ss.hasPermi('system:pro:export')")
    @Log(title = "工艺工序", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesTecPro mesTecPro)
    {
        List<MesTecPro> list = mesTecProService.selectMesTecProList(mesTecPro);
        ExcelUtil<MesTecPro> util = new ExcelUtil<MesTecPro>(MesTecPro.class);
        util.exportExcel(response, list, "工艺工序数据");
    }

    /**
     * 获取工艺工序详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pro:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(mesTecProService.selectMesTecProById(id));
    }

    /**
     * 新增工艺工序
     */
    @PreAuthorize("@ss.hasPermi('system:pro:add')")
    @Log(title = "工艺工序", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesTecPro mesTecPro)
    {
        return toAjax(mesTecProService.insertMesTecPro(mesTecPro));
    }

    /**
     * 修改工艺工序
     */
    @PreAuthorize("@ss.hasPermi('system:pro:edit')")
    @Log(title = "工艺工序", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesTecPro mesTecPro)
    {
        return toAjax(mesTecProService.updateMesTecPro(mesTecPro));
    }

    /**
     * 删除工艺工序
     */
    @PreAuthorize("@ss.hasPermi('system:pro:remove')")
    @Log(title = "工艺工序", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(mesTecProService.deleteMesTecProByIds(ids));
    }

//    @GetMapping("/getPros")
//    public AjaxResult getPros(@RequestParam String processid){
//        return success(mesTecProService.getPros(processid));
//    }


    //修改工艺工序接口
    @PutMapping("/mes/edit/TecPro")
    public AjaxResult editTecPro(@RequestBody MesTecPro mesTecPro){
        return toAjax(mesTecProService.editTecPro(mesTecPro));
    }

    //查看工艺拥有那些工序接口
    @GetMapping("/processIds")
    public AjaxResult selectProId(@RequestParam("tecId") String tecId) {
        List<String> processIds = mesTecProService.selectProId(tecId);
        return AjaxResult.success(processIds);
    }

}
